import { getMonthList, getAllList } from '@/services/attendance/overtime';

export default {
    namespace: 'overtime',
    state: {
        monthList: [],
        monthPagination: {
            // current: 1,
            // pageSize: 10,
            // total: 0
        },
        allList: [],
        allPagination: {
            current: 1,
            pageSize: 10,
            total: 0
        }
    },
    effects: {
        *fetchMonthList({ payload }, { call, put }) {
            const result = yield call(getMonthList, payload);

            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        monthList: result.data.rows,
                        monthPagination: {
                            pageSize: result.data.pageSize,
                            current: result.data.pageNo,
                            total: result.data.total
                        }
                    }
                });
            }
        },
        *fetchAllList({ payload }, { call, put }) {
            const result = yield call(getAllList, payload);

            if (result && result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        allList: result.data.rows,
                        allPagination: {
                            pageSize: result.data.pageSize,
                            current: result.data.pageNo,
                            total: result.data.total
                        }
                    }
                });
            }
        }
    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        }
    }
};
